import 'package:flutter/material.dart';
import 'package:flutter_vant/main.dart';

class VanInput extends HookWidget {
  final bool? autofocus;
  final Function()? onFocus;
  final Function()? onBlur;
  // 最大字数
  final int? maxlength;
  // 键盘类型
  final TextInputType? keyboardType;
  const VanInput(
      {Key? key,
      this.autofocus = false,
      this.onFocus,
      this.onBlur,
      this.maxlength = 6,
      this.keyboardType})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    FocusNode focusNode = FocusNode();
    useEffect(() {
      focusNode.addListener(() {
        if (focusNode.hasFocus) {
          onFocus?.call();
        } else {
          onBlur?.call();
        }
      });
      return () {
        focusNode.dispose();
      };
    }, [autofocus]);
    return TextField(
      decoration: null,
      focusNode: focusNode,
      cursorColor: Colors.black,
      maxLength: maxlength,
      keyboardType: keyboardType,
      autofocus: autofocus ?? false,
    );
  }
}
